package weeek12.topic04;

import com.hazelcast.collection.IList;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;

import java.util.Map;

public class HazelcastTest {
    public static void main(String[] args) {
        HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
        testMap(hazelcastInstance);
        testList(hazelcastInstance);
    }
    private static void testMap(HazelcastInstance hazelcastInstance) {
        Map<String, String> map = hazelcastInstance.getMap("test_map");

        for (int i = 0; i < 10; i++) {
            map.put("key"+i, "value"+i);

        }
        for (int i = 0; i < 10; i++) {
            System.out.println(map.get("key"+i));

        }
    }
    private static void testList(HazelcastInstance hazelcastInstance) {
        IList<Object> list = hazelcastInstance.getList("test_List");

        for (int i = 0; i < 10; i++) {
            list.add("it"+i);

        }
        System.out.println("size:"+list.size());
        for (int i = 0; i < 10; i++) {
            System.out.println(list.get(i));

        }
    }
}
